package com.th.supcom.pds.recipefee.server;

import java.util.ArrayList;
import java.util.List;

import net.carefx.framework.exception.BusinessException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.th.supcom.pds.domain.vo.PatientInfo;
import com.th.supcom.pds.domain.vo.PdsSupplyDetailVO;
import com.th.supcom.pds.domain.vo.PdsSupplyVO;
import com.th.supcom.pds.internal.client.model.MedicareCardAllInfoModel;
import com.th.supcom.pds.internal.client.model.MedicareCardPatientInfoModel;
import com.th.supcom.pds.sortingdrug.client.model.PdsPrescDetailInfoModel;

public class ObjectConvertUtils
{
    /**
     * PdsSupplyVO 转换为PdsPrescDetailInfoModel
     * 
     * @param list
     * @return add by Zli
     */
    public static PdsPrescDetailInfoModel getPrescModel (PdsSupplyVO pdsSupplyVO)
    {
        PdsPrescDetailInfoModel model = new PdsPrescDetailInfoModel ();
        model.setPrescId (pdsSupplyVO.getPrescId ());
        model.setPrescNo (pdsSupplyVO.getPrescNo ());
        model.setPrescSource (pdsSupplyVO.getPrescSource ());
        model.setOutpVisitId (pdsSupplyVO.getOutpVisitId ());
        model.setPatientId (pdsSupplyVO.getPatientId ());
        model.setPatiSex(pdsSupplyVO.getPatiSex());
        model.setPatiName(pdsSupplyVO.getPatiName());
        model.setVisitId (pdsSupplyVO.getVisitId ());
        model.setOrgIdExec (pdsSupplyVO.getOrgIdExec ());
        model.setOrgIdExecName (pdsSupplyVO.getOrgIdExecName ());

        model.setControlType (0);
        model.setOrderedBy (pdsSupplyVO.getOrderedBy ());
        model.setOrderByDeptName ("消化内科");
        model.setCheckFlag (pdsSupplyVO.getCheckFlag ());
        return model;
    }

    public static List <PdsPrescDetailInfoModel> getPrescModels (List <PdsSupplyVO> list)
    {
        List <PdsPrescDetailInfoModel> modelList = new ArrayList <PdsPrescDetailInfoModel> ();
        for (PdsSupplyVO pdsSupplyVO : list)
        {
            modelList.add (getPrescModel (pdsSupplyVO));
        }
        return modelList;
    }

    /**
     * PdsSupplyDetailVO 转换为PdsPrescDetailInfoModel
     * 
     * @param list
     * @return add by Zli
     */
    public static PdsPrescDetailInfoModel getPrescDetailModel (PdsSupplyDetailVO pdsSupplyDetailVO)
    {
        PdsPrescDetailInfoModel model = new PdsPrescDetailInfoModel ();
        model.setPrescNo (pdsSupplyDetailVO.getPrescNo ());
        model.setPhamName (pdsSupplyDetailVO.getPhamName ());
        model.setFactor (pdsSupplyDetailVO.getFactor ());
        model.setPhamStdCode (pdsSupplyDetailVO.getPhamStdCode ());
        model.setPhamSpec (pdsSupplyDetailVO.getPhamSpec ());
        model.setPackageUnit (pdsSupplyDetailVO.getPackageUnit ());
        model.setPackageUnitName (pdsSupplyDetailVO.getPackageUnitName ());
        model.setUnitQty (pdsSupplyDetailVO.getUnitQty ());
        model.setQtySum (pdsSupplyDetailVO.getQtySum ());
        model.setQtyUnit (pdsSupplyDetailVO.getQtyUnit ());
        model.setQtyUnitName (pdsSupplyDetailVO.getQtyUnitName ());
        model.setCosts (pdsSupplyDetailVO.getCosts ());
        model.setFreqCode (pdsSupplyDetailVO.getFreqCode ());
        model.setDosePerUnit (pdsSupplyDetailVO.getDosePerUnit ());
        model.setPerMedQty (pdsSupplyDetailVO.getPerMedQty ());
        model.setMedUnit (pdsSupplyDetailVO.getMedUnit ());
        model.setMedUnitName (pdsSupplyDetailVO.getMedUnitName ());
        model.setFreqCodeName (pdsSupplyDetailVO.getFreqCodeName ());
        model.setPackagePrice (pdsSupplyDetailVO.getPackagePrice () == null ? 1 : pdsSupplyDetailVO.getPackagePrice ());
        model.setPerformedBy (pdsSupplyDetailVO.getPerformedBy ());
        model.setPerformedByName (pdsSupplyDetailVO.getPerformedByName ());
        model.setUsageCod (pdsSupplyDetailVO.getUsageCod ());
        model.setIsGroupOrder (pdsSupplyDetailVO.getIsGroupOrder ());
        model.setSortNumber (pdsSupplyDetailVO.getSortNumber () == null ? 1 : pdsSupplyDetailVO.getSortNumber ());
        model.setStockFlag (pdsSupplyDetailVO.getStockFlag ());
        model.setTotalPrice (pdsSupplyDetailVO.getTotalPrice ());
        model.setCheckFlag (pdsSupplyDetailVO.getCheckFlag ());
        model.setSendDrugMode ("带走");
        return model;
    }

    public static List <PdsPrescDetailInfoModel> getPrescDetailModel (List <PdsSupplyDetailVO> list)
    {
        List <PdsPrescDetailInfoModel> modelList = new ArrayList <PdsPrescDetailInfoModel> ();
        for (PdsSupplyDetailVO pdsSupplyDetailVO : list)
        {
            modelList.add (getPrescDetailModel (pdsSupplyDetailVO));
        }
        return modelList;
    }

    public static MedicareCardAllInfoModel getPatientIno (PatientInfo patientIno)
    {
        MedicareCardAllInfoModel medicareCardAllInfoModel = new MedicareCardAllInfoModel ();
        MedicareCardPatientInfoModel medicareCardPatientInfoModel = new MedicareCardPatientInfoModel ();
        medicareCardPatientInfoModel.setName (patientIno.getName ());
        medicareCardPatientInfoModel.setSex (patientIno.getSex ());
        medicareCardPatientInfoModel.setDateOfBirth (patientIno.getBirthDate ());
        medicareCardPatientInfoModel.setPatientId (patientIno.getPatiId ());
        medicareCardAllInfoModel.setCardBalance (patientIno.getBalance ());

        medicareCardPatientInfoModel.setUpdateTime (patientIno.getVisitBeginDate ());
        medicareCardPatientInfoModel.setChargeType (patientIno.getChargeType ());
        medicareCardPatientInfoModel.setVisitId (patientIno.getVisitId ());
        medicareCardPatientInfoModel.setDeptName (patientIno.getDeptName ());
        medicareCardPatientInfoModel.setVisitDay (patientIno.getVisitDay ());
        medicareCardPatientInfoModel.setBedCode (patientIno.getBedCode ());
        medicareCardPatientInfoModel.setAge (patientIno.getAge ());
        medicareCardAllInfoModel.setMedicareCardPatientInfo (medicareCardPatientInfoModel);
        return medicareCardAllInfoModel;
    }

    /**
     * 日志记录器.
     */
    public static final Logger s_logger = LoggerFactory.getLogger (ObjectConvertUtils.class);
    /**
     * 公司版权信息.
     */
    public static final String copyright = "Copyright 2015, Carefx Corporation";

    /**
     * 提交路径.
     */
    public static final String SCC_BRANCH = "$URL$";

    /**
     * 提交日期.
     */
    public static final String SCC_LAST_MODIFICATION_DATE = "$Date$";

    /**
     * 最终修改人员.
     */
    public static final String SCC_LAST_MODIFIER_NAME = "$Author$";

    /**
     * 最终版本号.
     */
    public static final String SCC_REVISION = "$Revision$";

    /**
     * PdsPrescDetailInfoModel转换为 PdsSupplyVO
     * 
     * @param model
     * @return add by Zli
     */
    public static PdsSupplyVO getPdsSupply (PdsPrescDetailInfoModel prescmodel)
    {
        if (prescmodel == null)
        {
            throw new BusinessException ("处方主记录为空");
        }
        PdsSupplyVO pdsSupply = new PdsSupplyVO ();
        pdsSupply.setOrderedBy (prescmodel.getOrderedBy ());
        pdsSupply.setPrescId (prescmodel.getPrescId ());
        pdsSupply.setPrescNo (prescmodel.getPrescNo ());
        pdsSupply.setPrescType (prescmodel.getPrescType ());
        pdsSupply.setOutpVisitId (prescmodel.getOutpVisitId ());
        pdsSupply.setPatientId (prescmodel.getPatientId ());
        pdsSupply.setVisitId (prescmodel.getVisitId ());
        pdsSupply.setPatiName (prescmodel.getPatiName());
        pdsSupply.setPatiSex (prescmodel.getPatiSex ());
        pdsSupply.setPrescSource (prescmodel.getPrescSource () == null ? 1 : prescmodel.getPrescSource ());
        pdsSupply.setOrderName (prescmodel.getOrderName ());
        pdsSupply.setPxAmount (prescmodel.getPxAmount ());// 总剂数
        pdsSupply.setPxDaily (prescmodel.getPxDaily ());
        pdsSupply.setDosageForm (prescmodel.getDosageForm ());
        pdsSupply.setDosageFormAmount (prescmodel.getDosageFormAmount ());
        pdsSupply.setBoilFlag (prescmodel.getBoilFlag ());
        pdsSupply.setFreqCode (prescmodel.getFreqCode ());
        pdsSupply.setFreqTimeQty (prescmodel.getFreqTimeQty ());
        pdsSupply.setFreqName (prescmodel.getFreqName ());
        pdsSupply.setFreqMemo (prescmodel.getFreqMemo ());
        pdsSupply.setUsageId (prescmodel.getAdministration ());
        pdsSupply.setUsageName (prescmodel.getAdministrationName ());
        pdsSupply.setCheckFlag (prescmodel.getCheckFlag ());
        pdsSupply.setQualifiedType (prescmodel.getQualifiedType ());
        pdsSupply.setCheckDatetime (prescmodel.getCheckDatetime ());
        pdsSupply.setPrescClassfication (prescmodel.getPrescClassfication ());
        pdsSupply.setPrescType (prescmodel.getPrescType ());
        pdsSupply.setEmpIdBegDoct (prescmodel.getEmpIdBegDoct ());
        pdsSupply.setEmpNameBegDoct (prescmodel.getEmpNameBegDoct ());
        pdsSupply.setOrgIdExec (prescmodel.getOrgIdExec ());
        pdsSupply.setCreateDate (prescmodel.getCreateDate ());
        pdsSupply.setIsInvalid (prescmodel.getIsInvalid ());
        pdsSupply.setSendOrReturnFlag (prescmodel.getSendOrReturnFlag ());
        pdsSupply.setOrgIdHospital (prescmodel.getOrgIdHospital ());
        return pdsSupply;
    }

    public static List <PdsSupplyVO> getPdsSupplys (List <PdsPrescDetailInfoModel> modelList)
    {
        List <PdsSupplyVO> pdsSupplys = new ArrayList <PdsSupplyVO> ();
        if (modelList == null || modelList.isEmpty ())
        {
            throw new BusinessException ("处方主记录为空");
        }
        for (PdsPrescDetailInfoModel pdsPrescDetailInfoModel : modelList)
        {
            pdsSupplys.add (getPdsSupply (pdsPrescDetailInfoModel));
        }
        return pdsSupplys;
    }

    /**
     * PdsPrescDetailInfoModel转换为 PdsSupplyDetailVO
     * 
     * @param model
     * @return add by Zli
     */
    public static PdsSupplyDetailVO getPdsSupplyDetail (PdsPrescDetailInfoModel prescmodel)
    {
        if (prescmodel == null)
        {
            throw new BusinessException ("处方主记录为空");
        }
        PdsSupplyDetailVO pdsSupplyDetailVO = new PdsSupplyDetailVO ();
        pdsSupplyDetailVO.setPrescNo (prescmodel.getPrescNo ());
        pdsSupplyDetailVO.setPhamName (prescmodel.getPhamName ());
        pdsSupplyDetailVO.setPhamStdCode (prescmodel.getPhamStdCode ());
        pdsSupplyDetailVO.setIsGroupOrder (prescmodel.getIsGroupOrder ());
        pdsSupplyDetailVO.setSortNumber (prescmodel.getSortNumber ());
        pdsSupplyDetailVO.setPhamSpec (prescmodel.getPhamSpec ());
        pdsSupplyDetailVO.setUnitQty (prescmodel.getUnitQty ());
        pdsSupplyDetailVO.setPackageUnit (prescmodel.getPackageUnit ());
        pdsSupplyDetailVO.setQtySum (prescmodel.getQtySum ());
        pdsSupplyDetailVO.setQtyUnit (prescmodel.getQtyUnit ());
        pdsSupplyDetailVO.setCosts (prescmodel.getCosts ());
        pdsSupplyDetailVO.setFreqCode (prescmodel.getFreqCode ());
        pdsSupplyDetailVO.setPerMedQty (prescmodel.getPerMedQty ());
        pdsSupplyDetailVO.setMedUnit (prescmodel.getMedUnit ());
        pdsSupplyDetailVO.setMedUnitName (prescmodel.getMedUnitName ());
        pdsSupplyDetailVO.setFreqCodeName (prescmodel.getFreqCodeName ());
        pdsSupplyDetailVO.setFreqTimeQty (prescmodel.getFreqTimeQty ());
        pdsSupplyDetailVO.setPackagePrice (prescmodel.getPackagePrice ());
        pdsSupplyDetailVO.setFactor (prescmodel.getFactor ());
        pdsSupplyDetailVO.setDosePerUnit (prescmodel.getDosePerUnit ());
        pdsSupplyDetailVO.setPerformedBy (prescmodel.getPerformedBy ());
        pdsSupplyDetailVO.setTotalPrice (prescmodel.getTotalPrice ());
        return pdsSupplyDetailVO;
    }

    public static List <PdsSupplyDetailVO> getPdsSupplyDetails (List <PdsPrescDetailInfoModel> modelList)
    {
        List <PdsSupplyDetailVO> pdsSupplyDetails = new ArrayList <PdsSupplyDetailVO> ();
        if (modelList == null || modelList.isEmpty ())
        {
            throw new BusinessException ("传入的参数为空");
        }
        for (PdsPrescDetailInfoModel pdsPrescDetailInfoModel : modelList)
        {
            pdsSupplyDetails.add (getPdsSupplyDetail (pdsPrescDetailInfoModel));
        }
        return pdsSupplyDetails;
    }

}
